package cn.com.bsoft.cloud.dao.cloud;

import cn.com.bsoft.cloud.UseDatasourceCloud;
import cn.com.bsoft.cloud.entity.ScheduleSite;
import cn.com.bsoft.cloud.entity.ScheduleVideo;
import cn.com.bsoft.cloud.entity.cloud.DoctorInformation;
import cn.com.bsoft.cloud.entity.param.DoctorParam;
import cn.com.bsoft.cloud.entity.param.VideoParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@UseDatasourceCloud
public interface ScheduleSiteDao {

    @Select("<script> " +
            "SELECT s.yyid as appointmentID,p.deliveryStatus as deliveryStatus," +
            "s.psdbm as siteCode ,s.psdmc as siteName ,d.address as siteAddress " +
            "from t_appoint_site as s ,t_prescription_drug_list as p , t_distribution_site as d " +
            "where s.yyid=p.appointId AND s.psdbm=d.psdbm and s.yyid in" +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'> " +
            "   #{item} " +
            "</foreach>" +
            "</script> ")
    List<ScheduleSite> getScheduleStatus(@Param("ids") List<String> ids);

    @Select("<script> " +
            "select s.yyid as appointmentID,s.psdbm as siteCode ,s.psdmc as siteName ,d.address as siteAddress from t_appoint_site as s , t_distribution_site as d WHERE  d.psdbm =s.psdbm AND s.yyid  in" +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'> " +
            "   #{item} " +
            "</foreach>" +
            "</script> "
    )
    List<ScheduleSite> getScheduleSite(@Param("ids") List<String> ids);


    @Select("<script> " +
            "select s.yyid as appointmentID,s.psdbm as siteCode ,s.psdmc as siteName ,d.address as siteAddress from t_appoint_site as s , t_distribution_site as d WHERE  d.psdbm =s.psdbm AND s.yyid  in" +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'> " +
            "   #{item} " +
            "</foreach>" +
            "</script> "
    )
    List<ScheduleSite> getScheduleLoginName(@Param("ids") List<String> ids);


    @Select("<script> " +
            "SELECT appointId as appointmentID,videoStatus from t_prescription_appointment WHERE appointId in" +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'> " +
            "   #{item} " +
            "</foreach>" +
            "</script> "
    )
    List<ScheduleVideo> getScheduleVideoStatus(@Param("ids") List<String> ids);


    @Update("<script>"+
            "update t_prescription_appointment " +
            "SET appointId=#{param.appointmentID},videoStatus=#{param.videoStatus} " +
            "WHERE appointId=#{param.appointmentID}"+
            "</script>")
    Boolean updateVideoStatus(@Param("param")VideoParam param);


    @Select("<script>"+
            "SELECT logName,medicalInstitutionCode,medicalInstitutionName," +
            "doctorName,workNumber,identityCard,gender,departmentName,departmentCode,flag " +
            "FROM t_doctor_information" +
            "<where>" +
                "<if test=\"param != null and param.loginName!= null\">"+
                    "logName=#{param.loginName}" +
                "</if>"+
                "<if test=\"param != null and param.medicalInstitutionCode != null\">"+
                     "and medicalInstitutionCode=#{param.medicalInstitutionCode}" +
                "</if>"+
                "<if test=\"param != null and param.medicalInstitutionName != null\">"+
                    "and medicalInstitutionName=#{param.medicalInstitutionName}" +
                "</if>"+
                "<if test=\"param != null and param.doctorName != null\">"+
                    "and doctorName=#{param.doctorName}" +
                "</if>"+
                "<if test=\"param != null and param.workNumber != null\">"+
                    "and workNumber=#{param.workNumber}" +
                "</if>"+
                "<if test=\"param != null and param.identityCard != null\">"+
                    "and identityCard=#{param.identityCard}" +
                "</if>"+
                "<if test=\"param != null and param.departmentName != null\">"+
                    "and departmentName=#{param.departmentName}" +
                "</if>"+
                "<if test=\"param != null and param.departmentCode != null\">"+
                     "and departmentCode=#{param.departmentCode}" +
                "</if>"+
                "<if test=\"param != null and param.flag != null\">"+
                     "and flag=#{param.flag}" +
                "</if>"+
            "</where>" +
            "</script>")
    List<DoctorInformation> queryDoctorList(@Param("param")DoctorParam param);




}
